package foo.bar.blog.web.action.general;

import foo.bar.blog.web.action.BaseActionBean;
import foo.bar.blog.web.extension.BlogTypeConverter;
import foo.bar.blog.web.nonextension.RomeSyndicationResolution;
import foo.bar.blog.core.domain.Blog;
import foo.bar.blog.core.domain.Tag;
import foo.bar.blog.core.domain.User;
import foo.bar.blog.core.domain.Entry;
import foo.bar.blog.core.services.FeedsService;
import foo.bar.blog.core.services.FeedType;
import foo.bar.blog.radeox.DecoratedEntryTransformer;
import foo.bar.radeox.api.engine.RenderEngine;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.validation.Validate;
import net.sourceforge.stripes.validation.EnumeratedTypeConverter;
import net.sourceforge.stripes.util.UrlBuilder;
import net.sourceforge.stripes.integration.spring.SpringBean;
import com.sun.syndication.feed.synd.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Collections;

/**
 * @author tmjee
 * @version $Date$ $Id$
 */
public class BlogFeedsActionBean extends BaseActionBean {

    private FeedsService feedsService;

    @Validate(converter = BlogTypeConverter.class)
    private Blog blog;

    // rss_2.0 or atom_1.0
    @Validate(converter = EnumeratedTypeConverter.class)
    private FeedType feedType = FeedType.rss_2_0;

    @DefaultHandler
    public Resolution view() {
        SyndFeed feed = feedsService.produceBlogFeed(blog, feedType);
        return new RomeSyndicationResolution(feed);
    }


    @SpringBean("feedsService")
    public void setRenderEngine(FeedsService feedsService) {
        this.feedsService = feedsService;
    }


    public Blog getBlog() {
        return blog;
    }

    public void setBlog(Blog blog) {
        this.blog = blog;
    }

    public FeedType getFeedType() {
        return feedType;
    }

    public void setFeedType(FeedType feedType) {
        this.feedType = feedType;
    }
}
